package com.kj.tms.system.service.user.serviceImpl;


import com.kj.tms.common.bean.dto.Pager;
import com.kj.tms.common.bean.session.SessionManager;
import com.kj.tms.common.utils.constant.Consts;
import com.kj.tms.common.utils.uuid.IdGen;
import com.kj.tms.pri.system.user.dto.UserDto;
import com.kj.tms.pri.system.user.dto.UserLogDto;
import com.kj.tms.pri.system.user.dto.UserOrgRoleDto;
import com.kj.tms.pri.system.user.service.UserLogService;
import com.kj.tms.system.service.user.dao.UserLogMapper;
import com.kj.tms.system.service.user.dao.UserOrgRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

/**
 * Created by wzl on 2017/10/24.
 * 用户操作日志
 */
@Service
public class UserLogServiceImpl implements UserLogService {

    @Autowired
    private UserLogMapper userLogMapper;
    @Autowired
    private UserOrgRoleMapper userOrgRoleMapper;
    @Autowired
    private SessionManager sessionManager;

    /**
     * 查询用户操作记录日志
     *
     * @return Pager
     */
    @Override
    public Pager list( UserLogDto dto) {
        return null;
    }

    /**
     * 查询用户相关信息
     *
     * @param dto
     * @return
     */
    @Override
    public Pager listUserInfo( UserOrgRoleDto dto) {
        Pager pager = new Pager();
        dto.setStartSize((dto.getPageNo() - 1) * dto.getPageSize() + 1);
        dto.setEndSize(dto.getPageNo() * dto.getPageSize());
        pager.setRowCount(userOrgRoleMapper.getCounts(dto));
        pager.setResults(userOrgRoleMapper.listByCondition(dto));
        return pager;
    }

    /**
     * @see UserLogService#save(UserLogDto)
     */
    @Override
    public void save(UserLogDto userLog) {
        userLog.setLogId(IdGen.getId());
        userLog.setUserId(((UserDto) sessionManager.getAttribute(Consts.USER)).getUserId());
        userLog.setCreateTime(new Timestamp(System.currentTimeMillis()));
        userLogMapper.save(userLog);
    }
}
